package org.zoomdev.zoom.dao.adapters.parameter;

import org.zoomdev.zoom.dao.adapters.ParameterAdapter;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;

public class Instant2TimestampParameterAdapter implements ParameterAdapter<Instant> {

    public static final Instant2TimestampParameterAdapter ADAPTER = new Instant2TimestampParameterAdapter();

    @Override
    public void setNonnullParameter(PreparedStatement ps, int index, Instant data) throws SQLException {
        Timestamp timestamp = Timestamp.from(data);
        timestamp.setNanos(data.getNano());
        ps.setTimestamp(index, timestamp);
    }
}
